home *** CD-ROM | disk | FTP | other *** search
/ Trading on the Edge / Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin / pc / mac_file / vendor_d / neuralwa / nw2v50 / uio_if_d.c < prev    next >
Text File  |  1993-08-23  |  6KB  |  178 lines

  1. /*******************************************************************/
  2. /*                                                                 */
  3. /*    servif_d.c - SERVor InterFace platform Dependent (.) Code    */
  4. /*    Authors: John C. Fairman and John Guiver     Dec 7, 1990     */
  5. /*    Copyright 1990 by Neuralware Inc.                            */
  6. /*                                                                 */
  7. /*    $Author   :  $                                               */
  8. /*    $Date     :  $                                               */
  9. /*    $Source   :  $                                               */
  10. /*    $Revision :  $                                               */
  11. /*    $Log      :  $                                               */
  12. /*                                                                 */
  13. /*******************************************************************/
  14.  
  15. #define UIO_IF_D
  16.  
  17. #include "host.h"
  18. #define UIO_SERVER   1
  19. #define SERVER_EMULATOR_FILE  2
  20. #define SKIP_COMPAT_DATA  1
  21.  
  22. #include "userutl.h"
  23. #include "uio_strc.h"
  24. #include "uio_tran.h"
  25.  
  26. #include "uio_if_i.pro"
  27. #include "uio_if_d.pro"
  28.  
  29.  
  30. #include  <SetUpA4.h>
  31. #include  "macuio.redef"
  32.  
  33. IMPORT NINT IORtnC;
  34. typedef   long int (*LProcPtr)( );  /* Think C ProcPtr returns a short */
  35. typedef   int      (*myProcPtr)( );
  36. LProcPtr  stdio_funcs[MIO_MAX];   /* Host stdio/stdlib function pointers */
  37. myProcPtr Receive_request;    /* Address for requesting host */
  38.  
  39. /* Glue routines for redirecting calls to Host */
  40.  
  41. #define GLUE_ROUTINE(rout_num,\
  42.      type, ptr, name, \
  43.      t1,p1,n1,t2,p2,n2,t3,p3,n3,t4,p4,n4) \
  44. type  ptr name( n1,n2,n3,n4) \
  45. t1 p1 n1;\
  46. t2 p2 n2;\
  47. t3 p3 n3;\
  48. t4 p4 n4;\
  49. {\
  50.   type ptr ret_cde;\
  51.   ret_cde = (type ptr)stdio_funcs[rout_num]( (t1 p1)n1,\
  52.                        (t2 p2)n2,\
  53.                        (t3 p3)n3,\
  54.                        (t4 p4)n4 );\
  55.   return ret_cde;\
  56. }
  57. GLUE_ROUTINE(MIO_fseek,int, ,io_fseek,FILE,*,fp,long, ,offset,long, ,whence,int,,n4)
  58. GLUE_ROUTINE(MIO_ftell,long, ,io_ftell,FILE,*,fp,int,,n2,int,,n3,int,,n4)
  59. GLUE_ROUTINE(MIO_fopen,FILE,*,io_fopen,char,*,filename,char,*,mode,int,,n3,int,,n4)
  60. GLUE_ROUTINE(MIO_freopen,FILE,*,io_freopen,char,*,filename,char,*,mode,FILE,*,stream,int,,n4)
  61. GLUE_ROUTINE(MIO_fclose,int, ,io_fclose,FILE,*,fp,int,,n2,int,,n3,int,,n4)
  62. GLUE_ROUTINE(MIO_remove,int, ,io_remove,char,*,filename,int,,n2,int,,n3,int,,n4)
  63. GLUE_ROUTINE(MIO_rename,int, ,io_rename,char,*,old,char,*,new,int,,n3,int,,n4)
  64. GLUE_ROUTINE(MIO_tmpnam,char,*,io_tmpnam,char,*,s,int,,n2,int,,n3,int,,n4)
  65. GLUE_ROUTINE(MIO_fflush,int, ,io_fflush,FILE,*,stream,int,,n2,int,,n3,int,,n4)
  66. GLUE_ROUTINE(MIO_setvbuf,int, ,io_setvbuf,FILE,*,stream,char,*,buf,long,,mode,size_t,,size)
  67. GLUE_ROUTINE(MIO_fgetc,int, ,io_fgetc,FILE,*,stream,int,,n2,int,,n3,int,,n4)
  68. GLUE_ROUTINE(MIO_fgets,char,*,io_fgets,char,*,s,long,,n,FILE,*,stream,int,,n4)
  69. GLUE_ROUTINE(MIO_fputc,int, ,io_fputc,long,,c,FILE,*,stream,int,,n3,int,,n4)
  70. GLUE_ROUTINE(MIO_fputs,int, ,io_fputs,char,*,s,FILE,*,stream,int,,n3,int,,n4)
  71. GLUE_ROUTINE(MIO_ungetc,int, ,io_ungetc,long,,c,FILE,*,stream,int,,n3,int,,n4)
  72. GLUE_ROUTINE(MIO_fread,size_t, ,io_fread,void,*,ptr,size_t,,size,size_t,,nmemb,FILE,*,stream)
  73. GLUE_ROUTINE(MIO_fwrite,size_t, ,io_fwrite,void,*,ptr,size_t,,size,size_t,,nmemb,FILE,*,stream)
  74. GLUE_ROUTINE(MIO_fgetpos,int, ,io_fgetpos,FILE,*,stream,fpos_t,*,pos,int,,n3,int,,n4)
  75. GLUE_ROUTINE(MIO_fsetpos,int, ,io_fsetpos,FILE,*,stream,fpos_t,*,pos,int,,n3,int,,n4)
  76. GLUE_ROUTINE(MIO_calloc,void,*,io_calloc,size_t,,nmemb,size_t,,size,int,,n3,int,,n4)
  77. GLUE_ROUTINE(MIO_malloc,void,*,io_malloc,size_t,,size,int,,n2,int,,n3,int,,n4)
  78. GLUE_ROUTINE(MIO_realloc,void,*,io_realloc,void,*,ptr,size_t,,size,int,,n3,int,,n4)
  79.  
  80. #define GLUE_VOIDRTN(rout_num, name, t1,p1,n1,t2,p2,n2 ) \
  81. void  name( n1,n2) \
  82. t1 p1 n1;\
  83. t2 p2 n2;\
  84. {\
  85.   stdio_funcs[rout_num]( (t1 p1)n1,(t2 p2)n2);\
  86. }
  87.  
  88. GLUE_VOIDRTN(MIO_setbuf,io_setbuf,FILE,*,stream,char,*,buf)
  89. GLUE_VOIDRTN(MIO_free,io_free,void,*,ptr,int,,n2)
  90. GLUE_VOIDRTN(MIO_rewind,io_rewind,FILE,*,stream,int,,n2)
  91.  
  92. FILE *io_tmpfile( void )
  93. {
  94.   stdio_funcs[MIO_tmpfile]( );
  95. }
  96.  
  97. #define GLUE_FMT(rout_num, name, type)\
  98. int name( ptr, format, a1,a2,a3,a4,a5,a6,a7,a8,a9,\
  99.          b1,b2,b3,b4,b5,b6,b7,b8,b9,\
  100.          c1,c2,c3,c4,c5)\
  101. type  *ptr;\
  102. char  *format;\
  103. int  a1,a2,a3,a4,a5,a6,a7,a8,a9;\
  104. int  b1,b2,b3,b4,b5,b6,b7,b8,b9;\
  105. int  c1,c2,c3,c4,c5;\
  106. {\
  107.   int        ret_cde;\
  108.   ret_cde = (int)stdio_funcs[rout_num]( (type *)ptr, format,\
  109.        a1,a2,a3,a4,a5,a6,a7,a8,a9,\
  110.        b1,b2,b3,b4,b5,b6,b7,b8,b9,\
  111.        c1,c2,c3,c4,c5);\
  112.   return ret_cde;\
  113.  }
  114. GLUE_FMT(MIO_sprintf, io_sprintf, char)
  115. GLUE_FMT(MIO_fprintf, io_fprintf, FILE)
  116. GLUE_FMT(MIO_sscanf, io_sscanf, char)
  117. GLUE_FMT(MIO_fscanf, io_fscanf, FILE)
  118.  
  119.  
  120. /* FUNCTION */
  121. EXPORT VOID Send_request()
  122. {
  123.   Receive_request();
  124.   SetUpA4();    /* possibly A4 has been corrupted */
  125.   asm{ adda.l #4,sp } /* SetUpA4 pushes old unwanted A4 onto the stack; adjust SP */
  126. }
  127.  
  128. /* */
  129. /* FUNCTION */
  130. EXPORT NINT Receive_command(dtp)
  131. DATA_TRANSFER_AREA_T  *dtp; /* Data transfer ptr */
  132. {
  133.   RPC_AREA_T   *rpc;
  134.   
  135.   Data_transfer_ptr = dtp;
  136.   rpc = &(dtp)->RPC_area;
  137.   
  138.   if (rpc->request == (BUFFER_INT) CMD_CREATE) {
  139.   {
  140.     NINT    wx;
  141.  
  142.     /* Tell master about size of double so we can check consistency */
  143.     (rpc->all_arg_lists.createcmd).szof_uio_dbl = sizeof(long double);
  144.     
  145.     /* Set up NWorks function addresses for server requests */
  146.     
  147.     Receive_request = (myProcPtr) (rpc->all_arg_lists.createcmd).Receive_request;
  148.     
  149.     for (wx=0; wx< MIO_MAX; wx++) stdio_funcs[wx] =
  150.       (LProcPtr) (rpc->all_arg_lists.createcmd).stdio_funcs[wx];
  151.   }
  152.     rpc->request = (BUFFER_INT) REQ_ACKNOWLEDGE;
  153.   } else {
  154.     Handle_command();
  155.   }
  156.   return(1);
  157. }
  158.  
  159.  
  160. long main(dtp)
  161. DATA_TRANSFER_AREA_T  *dtp; /* Data transfer ptr */
  162. {
  163.   RememberA0();   /* to access resource global variables */
  164.   SetUpA4();
  165.  
  166.   Receive_command( dtp );
  167.   RestoreA4( );
  168. }
  169.  
  170. /* */
  171. /* FUNCTION */
  172. EXPORT VOID UIO_server_error(err_id)
  173. NINT err_id;
  174. {
  175.   Data_transfer_ptr->RPC_area.request = err_id;
  176. }
  177.  
  178.